package com.pavlinic.mylisp.javaLibrary;

import java.math.BigInteger;

import com.pavlinic.mylisp.Expression;
import com.pavlinic.mylisp.Function;
import com.pavlinic.mylisp.GlobalEvaluationContext;
import com.pavlinic.mylisp.ListExpression;

public class Lists {
	public static Expression first(ListExpression list) {
		return list.first();
	}
	public static ListExpression rest(ListExpression list) {
		return list.rest();
	}
	public static ListExpression append(ListExpression a, ListExpression b) {
		final ListExpression listExpression = new ListExpression();
		listExpression.addAll(a);
		listExpression.addAll(b);
		return listExpression;
	}
	
	public static ListExpression cons(Expression head, ListExpression tail) {
	  final ListExpression listExpression = new ListExpression();
	  listExpression.add(head);
	  listExpression.addAll(tail);
	  return listExpression;
	}
	
	
	public static Expression apply(Function function, ListExpression list) {
		//This is a major bug!!! Should include some kind of local evaluation context
		return function.call(list, GlobalEvaluationContext.getInstance());
	}
	
	public static BigInteger length(ListExpression list) {
		return BigInteger.valueOf(list.size());
	}
}
